<template>
  <div class="login-panel">
    <h1 class="title">峰锅后台管理系统</h1>
    <div class="tabs">
      <el-tabs type="border-card" stretch v-model="activeName">
        <!-- 账号登录 -->
        <el-tab-pane name="account">
          <template #label>
            <div class="label">
              <el-icon><UserFilled></UserFilled></el-icon>
              <span class="text">账号登录</span>
            </div>
          </template>
          <pane-account ref="accountRef"></pane-account>
        </el-tab-pane>

        <!-- 手机登录 -->
        <el-tab-pane name="phone">
          <template #label>
            <div class="label">
              <el-icon><Cellphone></Cellphone></el-icon>
              <span class="text">手机登录</span>
            </div>
          </template>
          <pane-phone></pane-phone>
        </el-tab-pane>
      </el-tabs>
    </div>
    <div class="controls">
      <el-checkbox v-model="isRemPwd" label="记住密码"></el-checkbox>
      <el-link type="primary">忘记密码</el-link>
    </div>
    <el-button class="login-btn" type="primary" size="large" @click="handleLoginBtnClick"
      >立即登录</el-button
    >
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import PaneAccount from './PaneAccount.vue'
import PanePhone from './PanePhone.vue'
import { localCache } from '@/utils/cache'
import { watch } from 'vue'

const activeName = ref('account')
const isRemPwd = ref<boolean>(localCache.getCache('isRemPwd') ?? false)
watch(isRemPwd, (newValue) => {
  localCache.setCache('isRemPwd', newValue)
  // console.log(localCache.getCache('isRemPwd'))
})

// typeof PaneAccount：构造函数具体的类型
// InstanceType<typeof PaneAccount>：构造函数创建出来的实例对象的类型
const accountRef = ref<InstanceType<typeof PaneAccount>>()
function handleLoginBtnClick() {
  if (activeName.value === 'account') {
    accountRef.value?.loginAction(isRemPwd.value)
  } else {
    console.log('phone')
  }
}
</script>

<style scoped lang="less">
.login-panel {
  // 1、align-items是针对每一个子项起作用，它的基本单位是每一个子项，在所有情况下都有效果
  // 2、align-content属性是将flex子项作为一个整体起作用，它的基本单位是子项构成的行
  // 只在两种情况下有效果：
  // ①子项多行且flex容器高度固定
  // ②子项单行，flex容器高度固定且设置了flex-wrap:wrap
  .title {
    margin-bottom: 10px;
    text-align: center;
  }
  .label {
    display: flex;
    justify-items: center;
    align-items: center;
    .text {
      margin-left: 4px;
    }
  }
  .controls {
    width: 100%;
    display: flex;
    justify-content: space-between;
  }
  .login-btn {
    width: 100%;
  }
}
</style>
